/*
 * * * Compile_AHK SETTINGS BEGIN * * *

[AHK2EXE]
Exe_File=C:\Dropbox\Code repositories\PM App Launcher (SF-svn)\Include\Spec Finder\specFinder.exe
Created_Date=1
Execution_Level=2
[VERSION]
Resource_Files=C:\Dropbox\Code repositories\PM App Launcher (SF-svn)\Resource\SPF_Icon.ico
Set_Version_Info=1
Company_Name=WSNH Apps
File_Description=Look up Halliburton material specs and quickly find/copy object heirarchies
File_Version=2.0.0.1
Inc_File_Version=0
Internal_Name=specFinder.exe
Legal_Copyright=WSNHapps
Original_Filename=specFinder.exe
Product_Name=AutoHotkey_L
Product_Version=1.1.5.3
Set_AHK_Version=1
[ICONS]
Icon_1=C:\Dropbox\Code repositories\PM App Launcher (SF-svn)\Resource\SPF_Icon.ico

* * * Compile_AHK SETTINGS END * * *
*/

;_____________________________________________________________________
;---------------------------------------------------------------------
;	Title: Spec Finder
;---------------------------------------------------------------------
;
;	Allows user to quickly look up part heirarchies and material
;	specs for use with part attributes in CWI. The program copies 
;	the specified information to the user's clipboard when a selection
;	is made.
;
;	(see SPF_ScreenShot.png)
;
;
;	Group: About
;		General script file information
;
;		- *Written By:* 	Rameen Bakhtiary
;		- *Last Modified:*	12/7/2011
;_____________________________________________________________________
;---------------------------------------------------------------------
#SingleInstance, Force
#NoEnv
SetWorkingDir, %A_ScriptDir%  
SendMode, Input 
SetTitleMatchMode, 2
Functions()



;*****************************************************************
;                    S C R I P T   S E T T I N G S
;
;
	;____________________________
	; 		PUBLIC FILE LOCATIONS
	;
	EPUB			=	\\corp.halliburton.com\team\WD\Business Development And Technology\General\Engineering Public
	APP_FOLDER		=	%EPUB%\PM App Launcher\Spec Finder
	INI_NAME		= 	SpecFinder.ini

	INI_PATH		= 	%APP_FOLDER%\%INI_NAME%
	
	
	;____________________________
	; 		SPLASH IMAGE SETTINGS
	;
	SPLASH_OPTIONS = zy10 w650 B2 bcred cw343434 ctf1f1f1 csred fm14 wm400 fs12 ws300
	SPLASH_TIMEOUT = 5000
;___________________________________________________________________
;*******************************************************************




;=================================================================
;                            SET TRAY ICON
;=================================================================
if A_IsCompiled
	menu, tray, icon, % A_ScriptFullPath, -159




;=================================================================
;                   GET  MATERIAL & HEIRARCHY LISTS
;=================================================================
	ini := new Ini(INI_PATH)
	matlist := Replace(ini.keys("Materials"), "`n", "|",  "All")
	hierList := Replace(ini.keys("Heirarchies"), "`n", "|",  "All")
	


;=================================================================
;                              BUILD GUI
;=================================================================
	
	; SET WIDTH
	GUI_WIDTH = 350
	LB_OPTS = x20 y+20 h380 w310
	
	
	Gui, Margin, 0, 0
	gui, Font, s12 w500, arial
	
	txtW := gui_width - 5
	Gui, Add, Text, x5 y10 w%txtW% h25 +Center +Section, DOUBLE-CLICK  TO  SELECT	
	Gui, Add, Tab2, x0 y+10 w%GUI_WIDTH% h450 , Material Specs|Part Hierarchies

	;_____________________
	; 		MATERIAL SPECS
	;
	Gui, Tab, Material Specs
	Gui, Add, ListBox, %lb_opts% vmat gmatSelect, %matlist%	
	
	;__________________
	; 		HEIRARCHIES
	;
	Gui, Tab, Part Hierarchies
	Gui, Add, ListBox, x20 y+20 h380 w310 vheirarch ghSelect, %hierList%

	;_______________
	; 		SHOW GUI
	;
	Gui, Show, h500, Material Specs
Return







;____________________________
; 		MATERIAL EVENT HANDLE
;
matSelect:
	gui, Submit, NoHide
	If (a_guievent<>"doubleclick" || ini.Materials[mat]="---")
		Return
	Gui, Submit
	gui, Destroy	
	Clipboard := ini.Materials[mat]
	splash("The material spec number is copied to your clipboard.`nPaste it anywhere.", SPLASH_OPTIONS)
ExitApp



;_____________________________
; 		HEIRARCHY EVENT HANDLE
;
hSelect:
	gui, Submit, NoHide		
	If (a_guievent<>"doubleclick" || ini.Heirarchies[heirarch] = "---")
		Return
	Gui, Submit
	gui, Destroy	
	Clipboard := ini.Heirarchies[heirarch]
	splash("The Heirarchy code is copied to your clipboard.`nPaste it into CWI.", SPLASH_OPTIONS)
ExitApp




;===================================================================================================
;	Function: splash
;		Display splash image that goes away on mouse click
;
;===================================================================================================
splash(_Txt, SPLASH_OPTIONS, _Pic=""){
	global SPLASH_TIMEOUT
	
	Sleep 200
	SplashImage, %_Pic%, %SPLASH_OPTIONS%, `n[Click anywhere to close this window], %_Txt%,, Century Gothic
	SetTimer, timeOut, %SPLASH_TIMEOUT%
	keywait, LButton, D
	SplashImage, off
	return
	
	
	timeOut:
		SplashImage, Off
	return
}
		


GuiEscape:
GuiClose:
ExitApp


;=================================================================
;                            INCLUDE FILES
;=================================================================
#Include %A_ScriptDir%\..\..\Util\_cIni.ahk